//entroll.js
//获取应用实例
const app = getApp()

Page({
  data: {
    name: "",
    phone: "",
    question: "",
    url:"http://xx.xcc98.cn/api/link",
    id:""
  },
  Name:function(e){
    this.setData({
      name: e.detail.value
    })
  },
  Phone: function (e) {
    this.setData({
      phone: e.detail.value
    })
  },
  Question: function (e) {
    this.setData({
      question: e.detail.value
    })
  },
  submit:function(){
    var name= this.data.name;
    var phone=this.data.phone;
    var question=this.data.question;
    var phoneOk =/^[1][3,4,5,7,8][0-9]{9}$/.test(phone);
    var openId= app.globalData.openId;
    if (name != "" && phoneOk){
    wx.request({
      url: this.data.url,
      method:"post",
      data:{
        "name":name,
        "phone":phone,
        "question":question,
        "pid":this.data.id,
        "openId": openId
      },
      success:function(){
        console.log("ok")
        wx.navigateTo({
          url: '/pages/success/success',
        })
      },
      fail:function(){
        console.log("no");
        wx.navigateTo({
          url: '/pages/fail/fail',
        })
      }
      
    })
   }else{
      wx.showModal({
        title: '信息错误！',
        content: '请填写正确的姓名和手机号！',
        showCancel:false
      })  
   }
   
  },
  onLoad:function(e){
    console.log(e)
    this.setData({
      id: e.id
    })
  }
})
